﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Barebones.Components;
using Barebones.Dependencies;
using Barebones.Communication.Messages;
using Microsoft.Xna.Framework;

namespace Meat.Rendering
{
    public class CameraMan : EngineComponent
    {
        List<Camera> m_Cameras = new List<Camera>();

        public override IEnumerable<Barebones.Dependencies.IDependency> GetDependencies()
        {
            yield return new Dependency<Camera>(CameraAdded, CameraRemoved);
        }

        protected override void OnOwnerSet()
        {
            base.OnOwnerSet();
        }

        void CameraAdded(Camera cam)
        {
            m_Cameras.Add(cam);

            if (m_Cameras.Count == 1)
                Owner.Forum.Fire<CameraSetMsg>(new CameraSetMsg() { Camera = m_Cameras.First() });
        }

        void CameraRemoved(Camera cam)
        {
            m_Cameras.Remove(cam);

            if (m_Cameras.Count == 0)
                Owner.Forum.Fire<CameraSetMsg>(new CameraSetMsg() { Camera = null });
        }
    }
}
